<template>
  <div>
    <slot name="header" />
    <p-table rowKey="mcode" :pagination="false" bordered :columns="columns" :data-source="tableData" style="margin-bottom: 20px;">
      <div slot="routerCode" slot-scope="row, records">
        <a @click="routerCodeClick(records)">{{records.routerCode}}</a>
      </div>
      <div slot="routerPt" slot-scope="row, records">
        <span>{{routerPtMap[records.routerPt]}}</span>
      </div>
      <div slot="routerStatus" slot-scope="row, records">
        <span>{{records.routerStatus === 1?'开启':'关闭'}}</span>
      </div>
    </p-table>
    <chart ref="chart" v-if="action !== 'create'" slot="chart" />
    <slot name="submit" />
  </div>
</template>

<script>
import { timestampToDatetime } from '@/utils/util'
import Chart from '../../processHost/platform/pc/chart.vue'
import mesPeProcess from "@/api/mesPeProcess";
const columns = [
  {
    title: '产品编码',
    key: 'mcode',
    dataIndex: 'mcode',
    ellipsis: true,
  },
  {
    title: '产品名称',
    key: 'mname',
    dataIndex: 'mname',
    ellipsis: true,
  },
  {
    title: '产品类别',
    key: 'productTypeName',
    dataIndex: 'productTypeName',
    ellipsis: true,
  },
  {
    title: '工艺路线编码',
    key: 'routerCode',
    dataIndex: 'routerCode',
    ellipsis: true,
    scopedSlots: { customRender: 'routerCode' },
  },
  {
    title: '工艺路线版本号',
    key: 'version',
    dataIndex: 'version',
    ellipsis: true,
  },
  {
    title: '修改说明',
    key: 'modifyDesc',
    dataIndex: 'modifyDesc',
    ellipsis: true,
  },
  {
    title: '修改依据',
    key: 'modifyBasis',
    dataIndex: 'modifyBasis',
    ellipsis: true,
  },
  {
    title: '审批',
    key: 'routerPt',
    dataIndex: 'routerPt',
    ellipsis: true,
    scopedSlots: { customRender: 'routerPt' },
  },
  {
    title: '状态',
    key: 'routerStatus',
    dataIndex: 'routerStatus',
    ellipsis: true,
    scopedSlots: { customRender: 'routerStatus' },
  },
  {
    title: '创建人',
    key: 'createBy',
    dataIndex: 'createBy',
    ellipsis: true,
  },
  {
    title: '创建日期',
    key: 'createTime',
    dataIndex: 'createTime',
    ellipsis: true,
  },
]

export default {
  name: 'craft',
  inject: ['action', 'processInstanceId'],
  components: { Chart },
  data () {
    return {
      columns,
      tableData: [],
      routerPtMap: {
        '1': '发行',
        '2': '审批中',
        '3': '待审核',
        '4': '被驳回',
      },
    }
  },
  created () {
    this.getMesPeProcessRouteList();
  },
  methods: {
    routerCodeClick(row){
      const { routerCode, version } = row;
      this.$router.push({
        path: '/work/mesPeProcess/processidx',
        query: {
          handle: "edit",
          look: "2",
          routerCode,
          version,
        },
      }); 
    },
    getMesPeProcessRouteList(){
      mesPeProcess.getMesPeProcessRouteList({
        processInstanceId: this.processInstanceId,
      }).then( res =>{
        if (res.code === 0){
          const curData = res.data.records || [];
          this.tableData = curData;
        }else {
          this.$message.error(res.msg);
        }
      });
    },
  }
}
</script>
